{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a970ab2c-b937-4bc1-9c30-0b4a1c183842",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[2mResolved \u001b[1m134 packages\u001b[0m \u001b[2min 4.21s\u001b[0m\u001b[0m\n",
      "\u001b[2mPrepared \u001b[1m4 packages\u001b[0m \u001b[2min 666ms\u001b[0m\u001b[0m\n",
      "\u001b[1m\u001b[33mwarning\u001b[39m\u001b[0m\u001b[1m:\u001b[0m \u001b[1mFailed to hardlink files; falling back to full copy. This may lead to degraded performance.\n",
      "         If the cache and target directories are on different filesystems, hardlinking may not be supported.\n",
      "         If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning.\u001b[0m\n",
      "\u001b[2mInstalled \u001b[1m4 packages\u001b[0m \u001b[2min 72ms\u001b[0m\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mblinker\u001b[0m\u001b[2m==1.9.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mflask\u001b[0m\u001b[2m==3.1.2\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mitsdangerous\u001b[0m\u001b[2m==2.2.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mwerkzeug\u001b[0m\u001b[2m==3.1.3\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "! uv add flask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a2a083bc-3fe6-45ce-9ed8-11df63e390b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app '__main__'\n",
      " * Debug mode: on\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\n",
      " * Running on http://127.0.0.1:5000\n",
      "Press CTRL+C to quit\n",
      " * Restarting with stat\n"
     ]
    },
    {
     "ename": "SystemExit",
     "evalue": "1",
     "output_type": "error",
     "traceback": [
      "An exception has occurred, use %tb to see the full traceback.\n",
      "\u001b[31mSystemExit\u001b[39m\u001b[31m:\u001b[39m 1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\111\\PyAIProject\\.venv\\Lib\\site-packages\\IPython\\core\\interactiveshell.py:3707: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
      "  warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "\n",
    "app = Flask(__name__)\n",
    "# app.debug=True 调试模式\n",
    "\n",
    "@app.route('/')\n",
    "def hello_world():\n",
    "    return 'Hello World!'\n",
    "    \n",
    "@app.route('/user/<username>')\n",
    "def show_user_profile(username):\n",
    "    # show the user profile for that user\n",
    "    return 'User %s' % username\n",
    "\n",
    "@app.route('/post/<int:post_id>')\n",
    "def show_post(post_id):\n",
    "    # show the post with the given id, the id is an integer\n",
    "    return 'Post %d' % post_id\n",
    "def do_the_login():\n",
    "    return '你执行了Post登录'\n",
    "def show_the_login_form():\n",
    "    name='王五'\n",
    "    return f'{name}get登录方法'\n",
    "@app.route('/login', methods=['GET', 'POST'])\n",
    "def login():\n",
    "    if request.method == 'POST':\n",
    "        #do_the_login()\n",
    "        return '你执行了Post登录'\n",
    "    else:\n",
    "        #show_the_login_form()\n",
    "        return '你执行了get登录'\n",
    "\n",
    "@app.route('/register', methods=['POST'])\n",
    "def register():\n",
    "    print(request.headers)\n",
    "    print(request.form)\n",
    "    print(request.form['name'])\n",
    "    print(request.form.get('name'))\n",
    "    print(request.form.getlist('name'))\n",
    "    print(request.form.get('nickname', default='little apple'))\n",
    "    return 'welcome'\n",
    "if __name__ == '__main__':\n",
    "    app.run(port=5000, debug=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ec2d386-fea1-4266-b21c-760f5b6cf68f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
